{% extends "base.html" %}
{% load static %}
{% load render_kinetics %}
{% load render_states %}



{% block title %}Path Reaction #{{ index }} - {{ network.title }}{% endblock %}

{% block navbar_items %}
<li><a href="{% url 'pdep:index' %}">Pressure Dependent Networks</a></li>
<li><a href="{% url 'pdep:network-index' networkKey=networkKey%}">{{ network.title }}</a></li>
<li><a href="{% url 'pdep:network-path-reaction' reaction=index networkKey=networkKey%}">Path Reaction #{{ index }}</a></li>
{% endblock %}

{% block sidebar_items %}
{% include "networkSidebar.html" %}
{% endblock %}

{% block page_title %}Path Reaction #{{ index }} - {{ network.title }}{% endblock %}

{% block extrahead %}
<script src="https://code.highcharts.com/6/highcharts.js"></script>
<script src="{% static 'js/highcharts.theme.js' %}" type="text/javascript"></script>

<script type="text/javascript">
jQuery(document).ready(function() {

    {% if kinetics %}
    var kseries = new Array();
    {{ kinetics|get_rate_coefficients:user }}
    {% include "kineticsModel.js" %}
    {% endif %}
    
    {% if conformer %}
    var Qseries = new Array();
    var rhoseries = new Array();
    var Vseries = new Array();
    {{ conformer|get_states_data:user }}
    {% include "statesModel.js" %}
    {% endif %}
    
    var Elist = {{ microcanonicalRates.Edata }};
    var kflist = {{ microcanonicalRates.kfdata }};
    var krlist = {{ microcanonicalRates.krdata }};

    var kmicroseries = new Array();
    var kdata;
    if (kflist.length > 0) {
        kdata = new Array();
        for (var i = 0; i < Elist.length; i++) {
            if (kflist[i] > 0)
                kdata.push([Elist[i]/1000., Math.log(kflist[i]) / Math.LN10]);
        }
        kmicroseries.push(['Forward', kdata]);
    }
    if (krlist.length > 0) {
        kdata = new Array();
        for (var i = 0; i < Elist.length; i++) {
            if (krlist[i] > 0)
                kdata.push([Elist[i]/1000., Math.log(krlist[i]) / Math.LN10]);
        }
        kmicroseries.push(['Reverse', kdata]);
    }
    
    plotMicroKinetics = function(id, kseries) {

        series = [];
        for (var i = 0; i < kseries.length; i++)
            series.push({
                name: kseries[i][0],
                data: kseries[i][1]
            });
        var legendEnabled = true;

        options = {
            chart: {
                renderTo: id,
                defaultSeriesType: 'line'
            },
            title: { text: 'Microcanonical rate coefficient' },
            xAxis: {
                title: { text: 'Energy (kJ/mol)' }
            },
            yAxis: {
                title: { text: 'Rate coefficient (s^-1)' },
                labels: {
                    formatter: function() {
                        exponent = Math.floor(this.value);
                        mantissa = Math.pow(10, this.value) / Math.pow(10, exponent);
                        return '' + Highcharts.numberFormat(mantissa, 2, '.', '') + '*10^' + Highcharts.numberFormat(exponent, 0, '.', '');
                    }
                }
            },
            legend: { enabled: legendEnabled },
            series: series,
            tooltip: {
                formatter: function() {
                    E = this.x; 
                    exponent = Math.floor(this.y);
                    mantissa = Math.pow(10, this.y) / Math.pow(10, exponent);

                    return 'k(' + Highcharts.numberFormat(E, 2, '.', '') +' kJ/mol) = ' +
                        Highcharts.numberFormat(mantissa, 2, '.', '') + '*10^' + Highcharts.numberFormat(exponent, 0, '.', '');
                }
            }
        }

        var chartk = new Highcharts.Chart(options);
    };

    
    MathJax.Hub.Queue(function() {
        {% if kinetics %}
        plotKinetics('plotk', kseries);
        {% endif %}
        {% if conformer %}
        plotPartitionFunction('plotQ', Qseries);
        plotDensityOfStates('plotRho', rhoseries);
        if (Vseries.length > 0)
            plotHinderedRotorPotential('plotV', Vseries);
        {% endif %}
        plotMicroKinetics('plotmicrok', kmicroseries);
    });

});
</script>
{% endblock %}

{% block page_body %}

<h2>Reaction</h2>

<p>
<table>
    <tr>
        <td class="reactants">{{ reactants|safe }}</td>
        <td class="reactionArrow">{{ arrow|safe }}</td>
        <td class="reactants">{{ products|safe }}</td>
    </tr>
    <tr>
        <td class="reactants">{% for reactant in reaction.reactants %}{{ reactant.label }}{% if not forloop.last %} + {% endif %}{% endfor %}</td>
        <td class="reactionArrow">{{ arrow|safe }}</td>
        <td class="reactants">{% for product in reaction.products %}{{ product.label }}{% if not forloop.last %} + {% endif %}{% endfor %}</td>
    </tr>
</table>
</p>

<h2>Transition-state energy</h2>

<p>{{ E0 }} kcal/mol</p>

{% if kinetics %}
<h2>High-Pressure Limit Kinetics</h2>
{{ kinetics|render_kinetics_math:user }}

<div id="plotk" style="width: 500px; height: 300px; margin: auto;"></div>

{% endif %}

{% if conformer %}
<h2>Transition State Degrees of Freedom</h2>
{{ conformer|render_states_math:user }}
    
<div id="plotQ" style="width: 500px; height: 300px; margin: auto;"></div>
<div id="plotRho" style="width: 500px; height: 300px; margin: auto;"></div>
{% if hasTorsions %}
<div id="plotV" style="width: 500px; height: 400px; margin: auto;"></div>
{% endif %}

{% endif %}

<h2>Microcanonical Rate Coefficient</h2>

<div id="plotmicrok" style="width: 500px; height: 400px; margin: auto;"></div>

{% endblock %}
